using System.Collections;
using System.Collections.Generic;
using QFramework;
using UnityEngine;

public class Dissolve : MonoBehaviour
{
    public Material Material;
    public static readonly int Color = Shader.PropertyToID("Color");
    public static readonly int Fade = Shader.PropertyToID("Fade");
    public Color DisolveColor;
    private void Start()
    {
        var material = Instantiate(Material);
        GetComponent<SpriteRenderer>().material = material;
        material.SetColor(Color, DisolveColor);
        ActionKit.Lerp(1, 0, 0.5f, (fade) =>
        {
            Material.SetFloat(Fade, fade);
            this.LocalScale(1 + (1 - fade) * 0.5f);
        })
        .Start(this, () =>
        {
            Destroy(material);
            this.DestroyGameObjGracefully();
        });
    }
}